<template>
  <div class="page_main">
    <el-form ref="searchForm" :inline="true" :model="searchForm" size="mini" class="searchForm">
      <search-form-box :show-more-btn="false" style="padding-left: 20px">
        <template slot="showSearch">
          <el-form-item label="编号" prop="code">
            <el-input v-model="searchForm.code" placeholder="请输入编号" clearable style="width: 200px"/>
          </el-form-item>
          <el-form-item label="楼盘" prop="building_area_id">
            <el-select v-model="searchForm.building_area_id" placeholder="请选择楼盘" clearable filterable
                       style="width: 200px"
            >
              <el-option v-for="item in buildingArr" :key="item.id" :label="item.name" :value="item.id"/>
            </el-select>
          </el-form-item>
          <el-form-item label="安装工" prop="worker_id">
            <el-select v-model="searchForm.worker_id" placeholder="请选择安装工" clearable filterable style="width: 200px">
              <el-option v-for="item in workerArr" :key="item.id" :label="item.name" :value="item.id"/>
            </el-select>
          </el-form-item>
          <el-form-item label="媒体类型" prop="media_type_id">
            <el-select v-model="searchForm.media_type_id" placeholder="请选择媒体类型" clearable filterable
                       style="width: 200px"
            >
              <el-option v-for="item in allMediaTypeArr" :key="item.id" :label="item.name" :value="item.id"/>
            </el-select>
          </el-form-item>
        </template>
        <template slot="searchBtn">
          <el-form-item>
            <el-button type="primary" plain @click="search">搜索</el-button>
            <el-button type="info" plain @click="resetForm(false)">重置</el-button>
          </el-form-item>
        </template>
      </search-form-box>
    </el-form>
    <el-pagination
      :current-page.sync="searchForm.page"
      :page-sizes="[5,10,20,50,100, 200, 400]"
      :page-size.sync="searchForm.page_size"
      layout="total, sizes, prev, pager, next, jumper"
      :total="changeParams.total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
    <div style="padding-left: 5px;margin: 10px 0">
      <el-button v-if="workerSubmitStatus=='WAIT_CHECK'" size="mini" type="primary" :disabled="selectRows.length==0"
                 @click="passBatch"
      >
        批量通过
      </el-button>
      <el-button v-if="workerSubmitStatus=='WAIT_CHECK'" size="mini" type="danger" :disabled="selectRows.length==0"
                 @click="noPassBatch"
      >
        批量不通过
      </el-button>
      <el-button v-if="workerSubmitStatus=='NOT_PASS'" size="mini" type="danger" :disabled="selectRows.length==0"
                 @click="revokeBatch"
      >
        批量撤销
      </el-button>

    </div>
    <div class="table_box">
      <el-table v-loading="changeParams.tableLoading" :data="tableDataArr" stripe size="mini" border
                header-row-class-name="table_header" @selection-change="handleSelectionChange"
      >
        <el-table-column v-if="workerSubmitStatus=='WAIT_CHECK' || workerSubmitStatus=='NOT_PASS'" type="selection" width="55"/>
        <el-table-column type="index" label="序号" align="center" width="50">
          <template slot-scope="scope">
            {{ (listParams.page - 1) * listParams.page_size + scope.$index + 1 }}
          </template>
        </el-table-column>
        <el-table-column label="照片" align="center" min-width="300">
          <template slot-scope="scope">
            <el-upload :ref="'upload'+scope.$index" style="display: none" :action="upFileUrl"
                       :headers="uploadHeaders"
                       :on-success="success" :show-file-list="false" :before-upload="beforeAvatarUpload"
                       :on-error="error"
            >
              <el-button size="mini" type="primary" slot="trigger" plain>替换</el-button>
            </el-upload>
            <div v-for="(item,index) in scope.row.photos" :key="item.url" style="display: inline-block">
              <el-image style="height: 280px;width: auto;margin: 10px"
                        :src="item.url" lazy
                        :preview-src-list="scope.row.photoList"
              />
              <div style="text-align: center">
                <el-button size="mini" slot="trigger" type="primary" plain
                           @click="replacePhoto(scope.$index,item,index)"
                >替换
                </el-button>
                <el-button type="danger" style="margin-left: 5px" size="mini" plain @click="removePhoto(item.id)">删除
                </el-button>
              </div>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="设备信息" align="center" min-width="300">
          <template slot-scope="scope">
            <el-row v-if="workerSubmitStatus=='WAIT_CHECK'" type="flex" justify="center">
              <el-form :ref="'point_form'+scope.row.id" :model="scope.row" size="mini" label-width="80px"
                       class="point_form" :rules="rules"
              >
                <el-col :span="12">
                  <el-form-item label="媒体编号" prop="code">
                    <div style="text-align: left;">
                      {{ scope.row.code }}
                    </div>
                  </el-form-item>
                  <el-form-item label="工单" prop="work_order_id">
                    <el-select v-model="scope.row.work_order_id" style="width: 250px"
                               @change="(val)=>{workOrderChange(val,scope.row)}"
                               :loading="scope.row.loading"
                               @focus="workOrderFocus(scope.row)"
                    >
                      <el-option v-for="order in scope.row.workOrderArr" :key="order.id" :value="order.id"
                                 :label="order.name"
                      />
                    </el-select>
                  </el-form-item>
                  <el-form-item label="安装工" prop="worker_name">
                    <div style="text-align: left;">
                      {{ scope.row.worker_name }}
                    </div>
                  </el-form-item>
                  <el-form-item label="类型" prop="worker_name">
                    <div style="text-align: left;">
                      <el-tag v-if="mediaInstallType =='INSTALL'" size="mini" type="success">新安装</el-tag>
                      <el-tag v-if="mediaInstallType =='PUBLISH'" size="mini">上刊</el-tag>
                      <el-tag v-if="mediaInstallType =='UNPUBLISH'" size="mini" type="danger">下刊</el-tag>
                      <el-tag v-if="mediaInstallType =='CHECK'" size="mini" type="warning">巡检</el-tag>
                      <el-tag v-if="mediaInstallType =='REPAIR'" size="mini" type="info">维修</el-tag>
                      <el-tag v-if="mediaInstallType =='REPLACE'" size="mini">换画</el-tag>
                      <el-tag v-if="mediaInstallType =='INTERMEDIATE_MONITORING'" size="mini" type="success">中间监播
                      </el-tag>
                    </div>
                  </el-form-item>
                  <el-form-item label="提交时间" prop="created_at">
                    <div style="text-align: left;">
                      {{ scope.row.created_at }}
                    </div>
                  </el-form-item>
                  <el-form-item label="备注" prop="remark">
                    <el-input v-model="scope.row.remark" style="width: 250px" placeholder="请输入备注"/>
                  </el-form-item>
                  <el-form-item label="故障与否" prop="breakdown_type">
                    <el-select v-model="scope.row.breakdown_type" style="width: 250px">
                      <el-option :value="0" label="完好"/>
                      <el-option :value="1" label="故障"/>
                    </el-select>
                  </el-form-item>
                  <el-form-item label="内部宽度" prop="size_width_inside">
                    <el-input v-model="scope.row.size_width_inside" style="width: 250px" placeholder="内部宽度">
                      <template slot="append">CM</template>
                    </el-input>
                  </el-form-item>
                  <el-form-item label="内部高度" prop="size_height_inside">
                    <el-input v-model="scope.row.size_height_inside" style="width: 250px" placeholder="内部高度">
                      <template slot="append">CM</template>
                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item v-if="mediaInstallType=='INSTALL'" label="楼盘" prop="building_area_id">
                    <el-select v-model="scope.row.building_area_id" style="width: 250px"
                               @change="(val)=>{buildingChange(val,scope.row)}"
                    >
                      <el-option v-for="building in scope.row.buildingArr" :key="building.buildingId"
                                 :value="building.buildingId" :label="building.buildName"
                      />
                    </el-select>
                  </el-form-item>
                  <el-form-item v-else label="楼盘" prop="building_area_name">
                    <div style="text-align: left;">
                      {{ scope.row.building_area_name }}
                    </div>
                  </el-form-item>
                  <el-form-item v-if="mediaInstallType=='INSTALL'" label="媒体类型" prop="media_type_id">
                    <el-select v-model="scope.row.media_type_id" style="width: 250px">
                      <el-option v-for="point in getPointArr(scope.row)"
                                 :key="point.mediaTypeId"
                                 :value="point.mediaTypeId" :label="point.mediaTypeName"
                      />
                    </el-select>
                  </el-form-item>
                  <el-form-item v-else label="媒体类型" prop="media_type_name">
                    <div style="text-align: left;">
                      {{ scope.row.media_type_name }}
                    </div>
                  </el-form-item>
                  <el-form-item label="宽度" prop="size_width">
                    <el-input v-model="scope.row.size_width" style="width: 250px">
                      <template slot="append">CM</template>
                    </el-input>
                  </el-form-item>
                  <el-form-item label="高度" prop="size_height">
                    <el-input v-model="scope.row.size_height" style="width: 250px">
                      <template slot="append">CM</template>
                    </el-input>
                  </el-form-item>
                  <el-form-item label="画面属性" prop="pic_type_id">
                    <el-select v-model="scope.row.pic_type_id" style="width: 250px" placeholder="请选择画面属性">
                      <el-option v-for="pic in picTypeArr" :key="pic.id" :value="pic.id" :label="pic.name"/>
                    </el-select>
                  </el-form-item>
                  <el-form-item v-if="scope.row.media_type_id==1" label="楼号" prop="building_number">
                    <el-input v-model="scope.row.building_number" style="width: 250px">
                      <template slot="append">号楼</template>
                    </el-input>
                  </el-form-item>
                  <el-form-item v-if="scope.row.media_type_id==1" label="单元号" prop="unit_number">
                    <el-input v-model="scope.row.unit_number" style="width: 250px">
                      <template slot="append">单元</template>
                    </el-input>
                  </el-form-item>
                  <el-form-item v-if="scope.row.media_type_id==1" label="楼层" prop="floor">
                    <el-select v-model="scope.row.floor" style="width: 250px">
                      <el-option v-for="floor in floorArr" :key="floor" :value="floor"/>
                    </el-select>
                  </el-form-item>
                  <el-form-item v-if="scope.row.media_type_id==1" label="楼栋类型" prop="building_type">
                    <el-select v-model="scope.row.building_type" style="width: 250px">
                      <el-option :value="1" label="多层"/>
                      <el-option :value="2" label="高层"/>
                    </el-select>
                  </el-form-item>
                  <el-form-item v-if="scope.row.media_type_id==9" label="门号" prop="door_number">
                    <el-input v-model="scope.row.door_number" style="width: 250px">
                      <template slot="append">号门</template>
                    </el-input>
                  </el-form-item>
                  <el-form-item v-if="scope.row.media_type_id==9" label="AB面" prop="ab_type_id">
                    <el-select v-model="scope.row.ab_type_id" style="width: 250px">
                      <el-option :value="57" label="A面"/>
                      <el-option :value="58" label="B面"/>
                    </el-select>
                  </el-form-item>
                  <el-form-item v-if="scope.row.media_type_id==9" label="是否亮灯" prop="is_light">
                    <el-select v-model="scope.row.is_light" style="width: 250px">
                      <el-option :value="0" label="不亮"/>
                      <el-option :value="1" label="亮灯"/>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col>
                  <el-form-item v-if="scope.row.breakdown_type === 1" label="故障原因" style="text-align: left">
                    <el-tag style="margin-right: 5px" v-for="(item,index) in scope.row.breakdown_type_name" :key="index"
                            size="mini"
                            type="danger"
                    >{{ item }}
                    </el-tag>
                  </el-form-item>
                </el-col>
              </el-form>
            </el-row>
            <el-row v-if="workerSubmitStatus!='WAIT_CHECK'" type="flex" justify="center">
              <el-form :model="scope.row" size="mini" label-width="80px" class="point_form">
                <el-col :span="12">
                  <el-form-item label="媒体编号" prop="code">
                    <div class="form_text_content">
                      {{ scope.row.code }}
                    </div>
                  </el-form-item>
                  <el-form-item label="工单" prop="work_order_name">
                    <div class="form_text_content">
                      {{ scope.row.work_order_name }}
                    </div>
                  </el-form-item>
                  <el-form-item label="安装工" prop="worker_name">
                    <div class="form_text_content">
                      {{ scope.row.worker_name }}
                    </div>
                  </el-form-item>
                  <el-form-item label="类型" prop="worker_name">
                    <div class="form_text_content">
                      <el-tag v-if="mediaInstallType =='INSTALL'" size="mini" type="success">新安装</el-tag>
                      <el-tag v-if="mediaInstallType =='PUBLISH'" size="mini">上刊</el-tag>
                      <el-tag v-if="mediaInstallType =='UNPUBLISH'" size="mini" type="danger">下刊</el-tag>
                      <el-tag v-if="mediaInstallType =='CHECK'" size="mini" type="warning">巡检</el-tag>
                      <el-tag v-if="mediaInstallType =='REPAIR'" size="mini" type="info">维修</el-tag>
                      <el-tag v-if="mediaInstallType =='REPLACE'" size="mini">换画</el-tag>
                      <el-tag v-if="mediaInstallType =='INTERMEDIATE_MONITORING'" size="mini" type="success">中间监播
                      </el-tag>
                    </div>
                  </el-form-item>
                  <el-form-item label="提交时间" prop="created_at">
                    <div class="form_text_content">
                      {{ scope.row.created_at }}
                    </div>
                  </el-form-item>
                  <el-form-item label="备注" prop="remark">
                    <div class="form_text_content">
                      {{ scope.row.remark }}
                    </div>
                  </el-form-item>
                  <el-form-item label="故障与否" prop="breakdown_type">
                    <div class="form_text_content">
                      {{ scope.row.breakdown_type == 0 ? '完好' : '故障' }}
                    </div>
                  </el-form-item>
                  <el-form-item label="内部宽度" prop="size_width_inside">
                    <div class="form_text_content">
                      {{ scope.row.size_width_inside }}CM
                    </div>
                  </el-form-item>
                  <el-form-item label="内部高度" prop="size_height_inside">
                    <div class="form_text_content">
                      {{ scope.row.size_height_inside }}CM
                    </div>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="楼盘" prop="building_area_name">
                    <div class="form_text_content">
                      {{ scope.row.building_area_name }}
                    </div>
                  </el-form-item>
                  <el-form-item v-if="mediaInstallType=='INSTALL'" label="媒体类型" prop="media_type_name">
                    <div class="form_text_content">
                      {{ scope.row.media_type_name }}
                    </div>
                  </el-form-item>
                  <el-form-item label="宽度" prop="size_width">
                    <div class="form_text_content">
                      {{ scope.row.size_width ? scope.row.size_width + 'CM' : '' }}
                    </div>
                  </el-form-item>
                  <el-form-item label="高度" prop="size_height">
                    <div class="form_text_content">
                      {{ scope.row.size_height ? scope.row.size_height + 'CM' : '' }}
                    </div>
                  </el-form-item>
                  <el-form-item label="画面属性" prop="pic_type_id">
                    <div class="form_text_content">
                      {{ scope.row.pic_type_name }}
                    </div>
                  </el-form-item>
                  <el-form-item v-if="scope.row.media_type_id==1" label="楼号" prop="building_number">
                    <div class="form_text_content">
                      {{ scope.row.building_number ? scope.row.building_number + '号楼' : '' }}
                    </div>
                  </el-form-item>
                  <el-form-item v-if="scope.row.media_type_id==1" label="单元号" prop="unit_number">
                    <div class="form_text_content">
                      {{ scope.row.unit_number ? scope.row.unit_number + '单元' : '' }}
                    </div>
                  </el-form-item>
                  <el-form-item v-if="scope.row.media_type_id==1" label="楼层" prop="floor">
                    <div class="form_text_content">
                      {{ scope.row.floor ? scope.row.floor + '层' : '' }}
                    </div>
                  </el-form-item>
                  <el-form-item v-if="scope.row.media_type_id==1" label="楼栋类型" prop="building_type">
                    <div class="form_text_content">
                      {{ scope.row.building_type == 1 ? '多层' : '高层' }}
                    </div>
                  </el-form-item>
                  <el-form-item v-if="scope.row.media_type_id==9" label="门号" prop="door_number">
                    <div class="form_text_content">
                      {{ scope.row.door_number ? scope.row.door_number + '号门' : '' }}
                    </div>
                  </el-form-item>
                  <el-form-item v-if="scope.row.media_type_id==9" label="AB面" prop="ab_type_id">
                    <div class="form_text_content">
                      {{ scope.row.ab_type_id == 57 ? 'A面' : 'B面' }}
                    </div>
                  </el-form-item>
                  <el-form-item v-if="scope.row.media_type_id==9" label="是否亮灯" prop="is_light">
                    <div class="form_text_content">
                      {{ scope.row.is_light == 0 ? '不亮' : '亮灯' }}
                    </div>
                  </el-form-item>
                </el-col>
                <el-col>
                  <el-form-item v-if="scope.row.breakdown_type === 1" label="故障原因" style="text-align: left">
                    <el-tag style="margin-right: 5px" v-for="(item,index) in scope.row.breakdown_type_name" :key="index"
                            size="mini"
                            type="danger"
                    >{{ item }}
                    </el-tag>
                  </el-form-item>
                </el-col>
              </el-form>
            </el-row>
          </template>
        </el-table-column>
        <el-table-column label="状态" align="center" width="80">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.flow_status==3" size="mini">审批</el-tag>
            <el-tag v-if="scope.row.flow_status==4" size="mini" type="success">通过</el-tag>
            <el-tag v-if="scope.row.flow_status==2" size="mini" type="danger">未通过</el-tag>
          </template>
        </el-table-column>
        <el-table-column v-if="workerSubmitStatus =='NOT_PASS'||workerSubmitStatus=='WAIT_CHECK'" label="操作"
                         align="center"
                         width="200"
        >
          <template slot-scope="scope">
            <el-button v-if="workerSubmitStatus=='WAIT_CHECK'" type="primary" size="mini" icon="el-icon-check"
                       @click="passOne(scope.row)"
            >通过
            </el-button>
            <el-button v-if="workerSubmitStatus=='WAIT_CHECK'" type="danger" size="mini" icon="el-icon-close"
                       @click="noPassOne(scope.row)"
            >不通过
            </el-button>
            <el-button v-if="workerSubmitStatus =='NOT_PASS'" type="danger" size="mini" icon="el-icon-delete"
                       @click="removeSubmit(scope.row)"
            >删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <el-pagination
      :current-page.sync="searchForm.page"
      :page-sizes="[5,10,20,50,100, 200, 400]"
      :page-size.sync="searchForm.page_size"
      layout="total, sizes, prev, pager, next, jumper"
      :total="changeParams.total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
</template>

<script>
import { upFileUrl } from '@/api/others'
import SearchFormBox from '@/components/SearchFormBox'
import { list_all_simple, list_media_types } from '@/api/building/building'
import { listWorker } from '@/api/workOrder/workOrder'
import {
  new_install_building_list_and_media_type,
  no_pass,
  pass, remove, removePhoto,
  replacePhoto,
  worker_order_list,
  revoke
} from '@/api/workOrder/workSubmit'
import { list_all3rd_bycode } from '@/api/business/setting/dict'
import { getToken } from '@/utils/auth'

export default {
  name: 'CheckTable',
  components: { SearchFormBox },
  props: {
    tableData: {
      type: Array,
      default() {
        return []
      }
    },
    mediaInstallType: {
      type: String,
      default: ''
    },
    workerSubmitStatus: {
      type: String,
      default: ''
    },
    currentWorkerSubmitStatus: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      searchForm: {
        page: 1,
        page_size: 5,
        workerSubmitStatus: this.workerSubmitStatus,
        mediaInstallType: this.mediaInstallType,
        code: null,
        building_area_id: null,
        worker_id: null,
        media_type_id: null
      },
      listParams: {
        page: 1,
        page_size: 5,
        workerSubmitStatus: this.workerSubmitStatus,
        mediaInstallType: this.mediaInstallType,
        code: null,
        building_area_id: null,
        worker_id: null,
        media_type_id: null
      },
      buildingArr: [],
      workerArr: [],
      allMediaTypeArr: [],
      changeParams: {
        total: null,
        tableLoading: false
      },
      tableDataArr: [],
      picTypeArr: [],
      selectRows: [],
      floorArr: ['5', '4', '3', '2', '1', '-1', '-2', '-3', '-4'],
      rules: {
        work_order_id: [
          { required: true, message: '工单不能为空', trigger: 'change' }
        ],
        building_area_id: [
          { required: true, message: '楼盘不能为空', trigger: 'change' }
        ],
        media_type_id: [
          { required: true, message: '媒体类型不能为空', trigger: 'change' }
        ],
        building_number: [
          { required: true, message: '楼号不能为空', trigger: 'blur' }
        ],
        unit_number: [
          { required: true, message: '单元号不能为空', trigger: 'blur' }
        ],
        floor: [
          { required: true, message: '楼层不能为空', trigger: 'change' }
        ],
        building_type: [
          { required: true, message: '楼栋类型不能为空', trigger: 'change' }
        ],
        door_number: [
          { required: true, message: '门号不能为空', trigger: 'blur' }
        ],
        ab_type_id: [
          { required: true, message: '请选择AB', trigger: 'change' }
        ],
        is_light: [
          { required: true, message: '请选择是否亮灯', trigger: 'change' }
        ],
        size_width_inside: [
          { required: true, message: '请输入内部宽度', trigger: 'blur' }
        ],
        size_height_inside: [
          { required: true, message: '请输入内部高度', trigger: 'blur' }
        ]
      },
      upFileUrl,
      uploadHeaders: {},
      tmpRow: null,
      loading: null
    }
  },
  watch: {
    tableData: {
      handler(data) {
        if (this.currentWorkerSubmitStatus === this.workerSubmitStatus) {
          this.tableDataArr = data.map(item => {
            return Object.assign({}, item)
          })
          this.$nextTick(() => {
            this.tableDataArr.forEach(item => {
              const form = this.$refs['point_form' + item.id]
              if (form != undefined) {
                form.clearValidate()
              }
            })
          })
          this.handlerResponseData(this.tableDataArr)
        }
      },
      deep: true
    }
  },
  created() {
    console.log(this.workerSubmitStatus)
    this.initALlMediaTypeArr()
    this.initBuildingArr()
    this.initWorkerArr()
    this.initPicTypeArr()
    if (getToken()) {
      this.uploadHeaders['Authorization'] = getToken()
    }
  },
  methods: {
    search() {
      this.searchForm.page = 1
      this.listParams = Object.assign({}, this.searchForm)
      this.getList()
    },
    getList() {
      this.$emit('search', this.listParams, this.changeParams)
    },
    resetListParams() {
      this.listParams.page = 1
      this.listParams.page_size = 5
      this.resetForm(true)
    },
    resetForm(flag = false) {
      this.$refs['searchForm'].resetFields()
      if (!flag) {
        this.listParams = Object.assign({}, this.searchForm)
        this.getList()
      }
    },
    initBuildingArr() {
      list_all_simple().then(res => {
        this.buildingArr = res.data
      })
    },
    initWorkerArr() {
      listWorker().then(res => {
        this.workerArr = res.data
      })
    },
    initALlMediaTypeArr() {
      list_media_types().then(res => {
        this.allMediaTypeArr = res.data
      })
    },
    handleSizeChange(val) {
      this.listParams.page_size = val
      this.getList()
    },
    handleCurrentChange(val) {
      this.listParams.page = val
      this.getList()
    },
    /**
     * 表格选择
     * @param val
     */
    handleSelectionChange(val) {
      this.selectRows = val
    },
    /**
     * 工单选择框改变事件
     * @param val
     * @param row
     */
    workOrderChange(val, row) {
      row.work_order_id = val
      if (this.mediaInstallType == 'INSTALL') {
        row.building_area_id = null
        row.media_type_id = null
        this.getBuildingList(row)
      }
    },
    /**
     * 楼盘选择框改变事件
     * @param val
     * @param row
     */
    buildingChange(val, row) {
      row.building_area_id = val
      row.media_type_id = null
    },
    getPointArr(row) {
      if (row.buildingArr != undefined) {
        const t = row.buildingArr.find(item => item.buildingId == row.building_area_id)
        if (t) {
          return t.mediaTypeVOList
        } else {
          return []
        }
      }
    },
    getBuildingList(row) {
      new_install_building_list_and_media_type({ workOrderId: row.work_order_id }).then(res => {
        row.buildingArr = res.data
      })
    },
    /**
     * 初始化画面属性
     */
    initPicTypeArr() {
      list_all3rd_bycode({ code: 'dwxg-hmsx' }).then(res => {
        this.picTypeArr = res.data
      })
    },
    /**
     * 处理后端数据
     * @param data
     */
    handlerResponseData(data) {
      if (this.workerSubmitStatus == 'WAIT_CHECK') {
        data.forEach(item => {
          this.$set(item, 'workOrderArr', [])
          this.$set(item, 'buildingArr', [])
          this.$set(item, 'workOrderArr', item.optionsVOList)
          this.$set(item, 'loading', false)
          if (this.mediaInstallType == 'INSTALL') {
            this.getBuildingList(item)
          }
        })
      }
    },
    /**
     * 通过一个
     */
    passOne(row) {
      this.$refs['point_form' + row.id].validate((valid) => {
        if (valid) {
          this.$confirm('确定通过？', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            const arr = []
            arr.push(row)
            this.pass(arr)
          }).catch(() => {

          })
        }
      })
    },
    noPassOne(row) {
      this.$confirm('确定不通过？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        const ids = []
        ids.push(row.id)
        this.noPass(ids)
      }).catch(() => {

      })
    },
    pass(arr) {
      const loading = this.$loading({
        lock: true,
        text: '提交中',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
      })
      pass({
        installType: this.mediaInstallType,
        workerSubmitList: arr
      }).then(res => {
        if (res.code == 200) {
          this.$message.success('操作成功')
          this.selectRows = []
          this.getList()
        }
        loading.close()
      }).catch(() => {
        loading.close()
      })
    },
    noPass(arr) {
      const loading = this.$loading({
        lock: true,
        text: '提交中',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
      })
      no_pass(arr).then(res => {
        if (res.code == 200) {
          this.$message.success('操作成功')
          this.selectRows = []
          this.getList()
        }
        loading.close()
      }).catch(() => {
        loading.close()
      })
    },
    revoke(arr) {
      const loading = this.$loading({
        lock: true,
        text: '提交中',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
      })
      revoke(arr).then(res => {
        if (res.code == 200) {
          this.$message.success('操作成功')
          this.selectRows = []
          this.getList()
        }
        loading.close()
      }).catch(() => {
        loading.close()
      })
    },
    /**
     * 批量通过
     */
    passBatch() {
      let flag = true
      this.selectRows.forEach(row => {
        this.$refs['point_form' + row.id].validate((valid) => {
          if (!valid) {
            flag = false
          }
        })
      })
      if (flag) {
        this.$confirm('确定通过？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.pass(this.selectRows)
        }).catch(() => {

        })
      }
    },
    /**
     * 批量不通过
     */
    noPassBatch() {
      this.$confirm('确定不通过？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        const arr = this.selectRows.map(item => {
          return item.id
        })
        this.noPass(arr)
      }).catch(() => {

      })
    },
    /**
     * 批量撤销
     */
    revokeBatch() {
      this.$confirm('确定撤销？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        const arr = this.selectRows.map(item => {
          return item.id
        })
        this.revoke(arr)
      }).catch(() => {

      })
    },
    removeSubmit(row) {
      this.$confirm('确定删除？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        const arr = [row.id]
        const loading = this.$loading({
          lock: true,
          text: '提交中',
          spinner: 'el-icon-loading',
          background: 'rgba(0, 0, 0, 0.7)'
        })
        remove(arr).then(res => {
          loading.close()
          this.getList()
          this.$message.success('操作成功')
        }).catch(() => {
          loading.close()
          this.$message.error('操作失败')
        })
      }).catch(() => {

      })
    },
    beforeAvatarUpload() {
      this.loading = this.$loading({
        lock: true,
        text: '替换中',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
      })
    },
    success(response) {
      replacePhoto({
        id: this.tmpRow.id,
        oldUrl: this.tmpRow.url,
        newUrl: response.data
      }).then(res => {
        this.loading.close()
        this.$emit('search', this.listParams, this.changeParams)
        this.tmpRow = null
      }).catch(() => {
        this.loading.close()
        this.tmpRow = null
      })
    },
    error() {
      this.loading.close()
      this.tmpRow = null
    },
    replacePhoto(index, row) {
      this.$confirm('确定更换照片?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.tmpRow = row
        this.$refs['upload' + index].$refs['upload-inner'].handleClick()
      }).catch(() => {

      })
    },
    removePhoto(id) {
      this.$confirm('删除后将无法恢复，请谨慎操作!', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'error'
      }).then(() => {
        const loading = this.$loading({
          lock: true,
          text: '操作中',
          spinner: 'el-icon-loading',
          background: 'rgba(0, 0, 0, 0.7)'
        })
        removePhoto({ id }).then(res => {
          loading.close()
          this.$emit('search', this.listParams, this.changeParams)
        }).catch(() => {
          loading.close()
        })
      }).catch(() => {

      })
    },
    workOrderFocus(row) {
      row.loading = true
      worker_order_list({ workerSubmitId: row.id }).then(res => {
        row.workOrderArr = res.data
        row.loading = false
      }).catch(() => {
        row.workOrderArr = []
        row.loading = false
      })
    }
  }
}
</script>

<style scoped>
/deep/ .table_header {
  font-weight: bold;
  color: black;
}

/deep/ .point_form .el-form-item {
  margin-bottom: 0;
}

.form_text_content {
  width: 300px;
  text-align: left;
}

/deep/ .el-form-item__error {
  position: relative;
  left: -89px;
  padding: 5px 0px;
}
</style>
